package com.ruoyi.h5.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.MiniSubject;
import com.ruoyi.system.domain.MiniSubjectHistory;
import com.ruoyi.system.domain.vo.h5.IncreaseRankingVO;
import com.ruoyi.system.domain.vo.h5.SubdivideSubjectVO;
import com.ruoyi.system.service.h5.IAllSubjectService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * 全部题材菜单接口
 * @author :liding
 * @date : 2023/11/16 10:47
 */
@RestController
@RequestMapping("/all")
@Slf4j
@Anonymous
public class AllSubjectController extends BaseController {
    @Autowired
    IAllSubjectService iAllSubjectService;

    /**
     * 左边的题材列表
     *
     * @return
     */
    @GetMapping("list")
    public AjaxResult<List<MiniSubject>> list() {
        return iAllSubjectService.list(1);
    }

    /**
     * 子题材列表
     *
     * @param parentId
     * @return
     */
    @GetMapping("child-tree/{parentId}")
    public AjaxResult<List<MiniSubject>> childTree(@PathVariable Long parentId) {
        return iAllSubjectService.childTree(parentId);
    }

    /**
     * 点击题材进入题材排名
     *
     * @param parentId
     * @return
     */
    @GetMapping("child-stock-tree/{parentId}")
    public AjaxResult<MiniSubject> childStockTree(@PathVariable Long parentId) {
        return iAllSubjectService.childStockTree(parentId);
    }

    /**
     * 细分题材
     *
     * @return
     * @Response com.ruoyi.common.core.domain.AjaxResult<com.ruoyi.system.domain.vo.h5.SubdivideSubjectVO>
     */
    @GetMapping("subdivideSubject")
    public AjaxResult<SubdivideSubjectVO> subdivideSubject() {
        return iAllSubjectService.subdivideSubject();
    }

    /**
     * 题材轮动
     *
     * @return
     */
    @GetMapping("subjectCircle")
    public AjaxResult<Map<String, List<MiniSubjectHistory>>> subjectCircle(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("type") String type) {
        return iAllSubjectService.subjectCircle(startDate, endDate, type);
    }

    /**
     * 每日复盘
     *
     * @return
     */
    @GetMapping("dailyReplay")
    public AjaxResult dailyReplay(@Param("day") String day) {
        return iAllSubjectService.dailyReplay(day);
    }

    /**
     * 新增概念
     *
     * @return
     */
    @GetMapping("addedStock")
    public AjaxResult addedStock(@Param("day") String day) {
        return iAllSubjectService.addedStock(day);
    }

    /**
     * 财务排名
     *
     * @param subjectId 题材id
     * @param quarter   季度
     * @param type
     * @return
     */
    @GetMapping("financialRank")
    public AjaxResult financialRank(@Param("subjectId") Long subjectId, @Param("year") String year, @Param("quarter") String quarter, @Param("type") String type) {
        return iAllSubjectService.financialRank(subjectId, year, quarter, type);
    }

    /**
     * 情绪排名
     *
     * @param subjectId 题材id
     * @param day       几日涨幅
     * @return
     */
    @GetMapping("emotionRank")
    public AjaxResult emotionRank(@Param("subjectId") Long subjectId, @Param("day") Integer day) {
        return iAllSubjectService.emotionRank(subjectId, day);
    }

    /**
     * 根据股票代码查题材图谱
     *
     * @param stockNo 股票代码
     * @return
     */
    @GetMapping("subjectTree")
    public AjaxResult<MiniSubject> subjectTree(@RequestParam("stockNo") String stockNo) {
        return iAllSubjectService.getSubjectTree(stockNo);
    }

    /**
     * 利润表
     *
     * @param stockNo 股票代码
     * @param quarter 报告季度，1:一季报，2：中报，3：三季报，4：年报
     * @return
     */
    @GetMapping("profitChart")
    public AjaxResult profitChart(@RequestParam("stockNo") String stockNo, @Param("quarter") String quarter) {
        return iAllSubjectService.profitChart(stockNo, quarter);
    }

    /**
     * 行业图谱
     *
     * @param stockNo 股票代码
     * @return
     */
    @GetMapping("industryPie")
    public AjaxResult industryPie(@RequestParam("stockNo") String stockNo) {
        return iAllSubjectService.industryPie(stockNo);
    }

    /**
     * 根据股票代码查所有相关题材
     *
     * @param stockNo 股票代码
     * @return
     */
    @GetMapping("stockSubjectList")
    public AjaxResult<List<MiniSubject>> stockSubjectList(@RequestParam("stockNo") String stockNo) {
        return iAllSubjectService.stockSubjectList(stockNo);
    }

    /**
     * 涨幅排名
     *
     * @param
     * @return
     */
    /*@GetMapping("IncreaseRanking")
    public TableDataInfo<IncreaseRankingVO> increaseRanking(@Param("day") String day, @Param("subjectId") Long subjectId) {
        // startPage();

        return getDataTable(iAllSubjectService.increaseRanking(day, subjectId));
    }*/

    @GetMapping("IncreaseRanking")
    public TableDataInfo<IncreaseRankingVO> increaseRanking(@RequestParam(value = "day",required = false)String day, @RequestParam("subjectId") Long subjectId) {
        return getDataTable(iAllSubjectService.increaseRanking(day, subjectId));
    }
}
